package com.pty.demo.behaviour.mediator;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author pengty
 * @date 2020/3/14
 */
public class TMallElfMediator implements HomeKitMediator {

    private static List<AbstractColleague> homeKitList = Lists.newArrayList();

    @Override
    public void register(AbstractColleague abstractColleague) {
        homeKitList.add(abstractColleague);
        System.out.println(abstractColleague.getName() + "注册成功.");
    }

    @Override
    public void relay(AbstractColleague abstractColleague) {
        System.out.println("我是中介者天猫精灵， 已经帮助" + abstractColleague.getName() + "转发消息啦");
        homeKitList.forEach(e -> {
            if (e != abstractColleague) {
                e.receive();
            }
        });
    }
}
